﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        var myApp = {};
        (function () {
            var id = 0;

            this.next = function () {
                return id++;
            };

            this.reset = function () {
                id = 0;
            }
        }).apply(myApp);

        window.console && console.log(
            myApp.next(),
            myApp.next(),
            myApp.reset(),
            myApp.next()
        ); //0, 1, undefined, 0
        
        /*
        var subsys1 = {}, subsys2 = {};
        var nextIdMod = function (startId) {
            var id = startId || 0;

            this.next = function () {
                return id++;
            };

            this.reset = function () {
                id = 0;
            }
        };

        nextIdMod.call(subsys1);
        nextIdMod.call(subsys2, 1000);

        window.console && console.log(
            subsys1.next(),
            subsys1.next(),
            subsys2.next(),
            subsys1.reset(),
            subsys2.next(),
            subsys1.next()
        ) //0, 1, 1000, undefined, 1001, 0
        */

        /*
        nextIdMod();
        window.console && console.log(
            next(),
            next(),
            reset(),
            next()
        ) //0, 1, undefined, 0
        */
    </script>
</head>
<body>
    
</body>
</html>
